using Framework.DataTable;
using System.Collections.Generic;
public partial class SceneTable : DataTableLoader<SceneData>
{
    public override string GetTableName() { return "Scene"; }
    protected override SceneData CreateItem()
    {
        return new SceneData();
    }
    public SceneTable()
    {
        _branchs = new List<string>() { "" };
    }
#if true
    private Dictionary<int, int> _keyToIndex;
    protected override void BuildIndex()
    {
        base.BuildIndex();
        if (_keyToIndex == null)
        {
            _keyToIndex = new Dictionary<int, int>(ItemCount);
        }
        else
        {
            _keyToIndex.Clear();
        }
        var len = DataList.Count;
        for (int i = 0; i < len; i++)
        {
            var item = DataList[i];
            if (item == null)
            {
                break;
            }
            if (_keyToIndex.ContainsKey(item.Id))
            {
                UnityEngine.Debug.LogErrorFormat("{0} 存在相同的索引 {1}", FileName, item.Id);
                continue;
            }
            _keyToIndex.Add(item.Id, i);
        }
    }
    public SceneData Get(int key)
    {
        if (_keyToIndex != null && _keyToIndex.TryGetValue(key, out int index))
        {
            return GetItem(index);
        }
        return null;
    }
#endif
}
public partial class SceneData
{
    public int Id { get; protected set; }
    /// <summary>
    ///地图名
    /// </summary>
    public string Name { get; protected set; }
    /// <summary>
    ///路径
    /// </summary>
    public string Path { get; protected set; }
    /// <summary>
    ///退出点
    /// </summary>
    public SceneExitData[] ExitPoint { get; protected set; }
}
public partial class SceneData : IDataTable
{
    public virtual void Decode(Framework.ByteArray buffer)
    {
        Id = buffer.ReadInt();
        Name = buffer.ReadString();
        Path = buffer.ReadString();
        ExitPoint = new SceneExitData[buffer.ReadUshort()]; for (var i = 0; i < ExitPoint.Length; i++) { ExitPoint[i] = SceneExitData.Decode(buffer); }
    }
}
#if UNITY_EDITOR
public partial class SceneData : IDataTable
{
	public void Parse(string[] values)
	{
        Id = Framework.Utils.Parse.ParseInt(values[0]);
        Name = values[1];
        Path = values[2];
        if (Framework.Utils.Parse.ParseList(values[3]) is string[] s_ExitPoint) { ExitPoint = new SceneExitData[s_ExitPoint.Length]; for (int i = 0; i < s_ExitPoint.Length; i++) { ExitPoint[i] = SceneExitData.DeserializeObject(s_ExitPoint[i]); } }
	}
    public void Encode(Framework.ByteArray buffer)
    {
        buffer.Write(Id);
        buffer.Write(Name);
        buffer.Write(Path);
        if (ExitPoint != null) { buffer.Write((ushort)ExitPoint.Length); for (var i = 0; i < (ushort)ExitPoint.Length; i++) { SceneExitData.Encode(ExitPoint[i], buffer); } } else { buffer.Write((ushort)0); }
    }
}
#endif